#include <iostream>
using std::cout;
using std::endl;

class A{
public:
    A(){ cout << "A()" << endl;}
    ~A(){ cout << "~A()" << endl;}
    void print() const{
        cout << "A::print()"  << endl;
    }
protected:
    long _a = 0;
};

class B
: virtual public A
{
public:
    B(){ cout << "B()" << endl;}
    ~B(){ cout << "~B()" << endl;}

protected:
    long _b = 0;
};

class C
: virtual public A
{
public:
    C(){ cout << "C()" << endl;}
    ~C(){ cout << "~C()" << endl;}
protected:
    long _c = 0;
};

class D
: public C
, public B
{
public:
    //初始化一定是ABCD的顺序
    //中间层基类的初始化顺序只与继承顺序有关
    D()
    : A()
    , C()
    , B()
    { cout << "D()" << endl;}
    ~D(){ cout << "~D()" << endl;}
    /* void print() const{ */
    /*     cout << "A::print()"  << endl; */
    /* } */
protected:
    long _d = 0;
};


void test0(){
    D d;
    d.print();
    
    /* cout << sizeof(A) << endl; */
    /* cout << sizeof(B) << endl; */
    /* cout << sizeof(C) << endl; */
    /* cout << sizeof(D) << endl; */

    /* d.A::print(); */
    /* d.B::print(); */
    /* d.C::print(); */
}

int main(void){
    test0();
    return 0;
}
